package github.leavesczy.reactivehttpsamples.ui.resultdetail

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.JsonUtils
import com.chad.library.adapter4.QuickAdapterHelper
import com.google.gson.Gson
import com.google.gson.JsonObject
import github.leavesczy.reactivehttpsamples.adapter.BridgeResultDetailAdapter
import github.leavesczy.reactivehttpsamples.adapter.BridgeResultImageAdapter
import github.leavesczy.reactivehttpsamples.base.BaseActivity
import github.leavesczy.reactivehttpsamples.core.mode.BridgeRecordItem
import github.leavesczy.reactivehttpsamples.core.mode.ResulData

import github.leavesczy.reactivehttpsamples.core.viewmodel.main.HomeViewModel
import github.leavesczy.reactivehttpsamples.databinding.ActivityResultDetailBinding
import github.leavesczy.reactivehttpsamples.databinding.AdapterResultDetailItemBinding
import github.leavesczy.reactivehttpsamples.widget.divider.ItemSpaceDecoration
import github.leavesczy.reactivehttpsamples.widget.view.HeaderView
import org.json.JSONObject

class ResultDetailActivity : BaseActivity() {

    override val bind by getBind<ActivityResultDetailBinding>()

    private val viewModel by getViewModel<HomeViewModel>()

    private val adapter= BridgeResultDetailAdapter()

    private val imageAdapter= BridgeResultImageAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)



        initView()

        initRecycleView()

        initData()

    }

    private fun initRecycleView() {

        bind.rvResult.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        bind.rvResult.adapter=adapter

        //头部信息
//       val headViewBind=AdapterResultDetailItemBinding.inflate(LayoutInflater.from(this))
//        headViewBind.tvFieldOne.text="振型阶数"
//        headViewBind.tvFieldTwo.text="固有频率(Hz)"
//        headViewBind.tvFieldOne.text="振型阻尼比"
//        headViewBind.tvFieldOne.text="模态质量(t)"
//
//        bind.rvResult.addView(headViewBind.root)

        bind.rvImage.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        bind.rvImage.addItemDecoration(ItemSpaceDecoration(this,ItemSpaceDecoration.VERTICAL_LIST,20,true))
        bind.rvImage.adapter=imageAdapter
    }

    private fun initView() {
        bind.headerView.init(this)

    }

    private fun initData() {
        val bundle = intent.extras
        val item = bundle?.getSerializable("item") as BridgeRecordItem


        item?.let {
            bind.headerView.setTitle(it.bridgeName)

            val datas = JSON.parseArray(it.resultJson, ResulData::class.java)

            adapter.submitList(datas?:ArrayList<ResulData>())

            imageAdapter.submitList(it.images)
        }


    }

}